/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 2e5;

int a[maxn + 2], b[maxn + 2];
int buk[maxn * 2 + 2];

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
      cin >> b[i];
    }
    a[n + 1] = b[n + 1] = 0;
    int last = 1;
    int max = 1;
    for (int i = 2; i <= n + 1; ++i) {
      if (a[i] != a[i - 1]) {
        buk[a[i - 1]] = std::max(buk[a[i - 1]], i - last);
        max = std::max(max, i - last);
        last = i;
      }
    }
    last = 1;
    for (int i = 2; i <= n + 1; ++i) {
      if (b[i] != b[i - 1]) {
        max = std::max(buk[b[i - 1]] + i - last, max);
        last = i;
      }
    }
    cout << max << '\n';
    last = 1;
    for (int i = 2; i <= n + 1; ++i) {
      if (a[i] != a[i - 1]) {
        buk[a[i - 1]] = 0;
        last = i;
      }
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B. Array merging.in", "r", stdin);
  freopen("B. Array merging.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
